package homwork4_8.service.impl;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class Proxy implements InvocationHandler {
    private Object target;
    public Proxy(Object target){
        this.target = target;
    }
    public Object getProxy(){
        return java.lang.reflect.Proxy.newProxyInstance(
                target.getClass().getClassLoader(), //目标对象类加载器
                target.getClass().getInterfaces(),//目标对象实现接口列表
                this //InvocationHandler 接口实现类对象
        );
    }
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

        //目标对象的执行方法
        Object o =  method.invoke(this.target,args);
        return o;
    }
}
